//
// Created by WangPeng on 2024/8/15.
//

#ifndef RTSP_H264_SERVER_POLLER_H
#define RTSP_H264_SERVER_POLLER_H

#include <poll.h>
#include <functional>
#include <atomic>
#include <memory>


class CServSocket;
class CPoller
{
public:
    static CPoller* get_instance()
    {
        static CPoller instance;
        return &instance;
    }
private:
    CPoller();
public:
    ~CPoller();
    int start_rtsp_serv();

private:
    static std::string read_from_fd(int fd);
    static int send_all(int fd, const std::string& response);
private:
    const int timeout_{1000};
    static const int MAX_FDS = 2;
    struct pollfd fds_[MAX_FDS]{};
    int nfds_{MAX_FDS};
    std::atomic_bool stop_{false};
    std::unique_ptr<CServSocket> serv_;
};



#endif //RTSP_H264_SERVER_POLLER_H
